package com.sfddata.musicpillow.common.respose;

import com.sfddata.musicpillow.common.constant.BizCodeEnum;

import java.io.Serializable;

/**
 * Created by jiaqiZHou
 * on 2020/12/4
 */
public class BaseRespose<T> implements Serializable {

    private static final long serialVersionUID = 2484868567614623456L;
    public int code;
    public T data;
    public String msg;

    public  BaseRespose<T> error(int code, String msg){

        BaseRespose<T> respose = new BaseRespose<>();
        respose.setCode(code);
        respose.setMsg(msg);
        return respose;

    }

    public  BaseRespose<T> ok(){
        BaseRespose<T> respose = new BaseRespose<>();
        respose.setCode(BizCodeEnum.SUCCESS.getCode());
        respose.setMsg(BizCodeEnum.SUCCESS.getMsg());
        return respose;
    }

    public BaseRespose<T> ok(T sub){
        BaseRespose<T> respose = new BaseRespose<>();

        respose.setCode(BizCodeEnum.SUCCESS.getCode());
        respose.setMsg(BizCodeEnum.SUCCESS.getMsg());
        respose.setData(sub);
        return respose;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }



    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 请求成功
     *
     * @return
     */
    public boolean isSuccess() {
            return 10000 == code;
    }

    public boolean isRelogin() {
        return 20001 == code || 20003==code || 20004==code;
    }
}
